import { handler } from './handlers.js'
import { isObject } from './utils.js'

const targetMap = new WeakMap()

export function reactive(target) {
  if (!isObject(target)) {
    return target
  }
  // 传入相同的对象，公用一个代理
  if (targetMap.has(target)) {
    return targetMap.get(target)
  }
  const proxy = new Proxy(target, handler)
  targetMap.set(target, proxy)
  return proxy
}